package com.gin.consumer.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.rpc.RpcContext;
import com.gin.api.service.DemoService;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;


@RestController
public class HelloController {

  //check = false 跳过检查，check 检查提供者是否有在zookeeper注册，如果没有则抛出异常
  @Reference(
          version = "${demo.service.version}",
          loadbalance = "roundrobin",
          group = "other",
          async = true
  )
  DemoService demoService;
  @RequestMapping("/sayHello")
  public Object sayHello(@RequestParam String name) throws InterruptedException, ExecutionException {
    demoService.sayHello(name);
    Future<String> helloFuture = RpcContext.getContext().getFuture();

    demoService.sayGoodBye(name);
    Future<String> goodByeFuture = RpcContext.getContext().getFuture();


    System.out.println(helloFuture.get());
    System.out.println(goodByeFuture.get());
    String messages =helloFuture.get() +"-"+goodByeFuture.get();
    return messages;
  }
}
